#!/bin/sh
# - runtime
# - test
# - mode
# - nr_task
# - no_affinity
# - smt

## It Scale takes a testcase and runs it from 1 through to n
## parallel copies to see if the testcase will scale. It
## builds both a process and threads based test in order
## to see any differences between the two.

cd $BENCHMARK_ROOT/will-it-scale || exit

setup_params()
{
	iterations=$((3 + nr_node))
	duration=$(( runtime / iterations / 2 - WARMUP_ITERATIONS ))
	[ "$duration" -lt 5  ] && duration=5
}

[ -n "$mode" ] || mode='both'
[ -n "$runtime" ] || runtime=300
[ -n "$smt" ] || smt=0
WARMUP_ITERATIONS=5 # defined in will-it-scale/main.c

if [ -n "$nr_task" ]; then
	# one shot run
	duration=$(( runtime - WARMUP_ITERATIONS ))
	threads_to_iterate=$nr_task
else
	. $LKP_SRC/lib/sysinfo.sh
	setup_threads_to_iterate
	setup_params
fi

[ -n "$no_affinity" ] || no_affinity=0

ulimit -n 65536

log_cmd /lkp/benchmarks/python3/bin/python3 ./runtest.py $test $duration $mode $no_affinity $smt $threads_to_iterate
